import router from '@/router';
import { messInfoRemind } from '@/api/friendcircle';
import { ElMessage, ElButton } from 'element-plus';
import { ITableRow } from '../interface';

const statusColorOption = {
    // 未发表
    0: '#ccc',
    // 已发表
    1: '#32D1AD'
};

/**
 * @description: 提醒发送
 * @param {any} row
 * @return {*}
 */
const remindMessFn = (row: any) => {
    messInfoRemind({
        work_user_id: row.work_user_id,
        send_moment_id: router.currentRoute.value.query.id,
        task_id: row.id
    }).then((res: any) => {
        ElMessage({
            message: '提醒发送成功',
            type: 'success',
            duration: 2000
        });
    });
};

/**
 * 表格配置
 */
const detailParticularsTableOption = (isExpired = false) => [
    {
        prop: 'work_user_name',
        label: '成员姓名',
        showOverflowTooltip: true
    },
    {
        prop: 'publish_status',
        label: '任务状态',
        render({ row }: ITableRow) {
            return (
                <div
                    class="status-point"
                    style={{
                        '--status-bgcolor': statusColorOption[row.publish_status] ?? '#ccc'
                    }}>
                    {row.publish_status === 0 ? '未发表' : '已发表'}
                </div>
            );
        }
    },
    {
        prop: 'like_nums',
        label: '点赞数',
        sortable: 'sortable'
    },
    {
        prop: 'comment_nums',
        label: '评论数',
        sortable: 'sortable'
    },
    {
        prop: 'comment_user_nums',
        label: '评论人数',
        sortable: 'sortable'
    },
    {
        prop: 'operate',
        label: '操作',
        width: 160,
        fixed: 'right',
        isOperate: true,
        renderOperate({ row }: any) {
            return !isExpired && row.publish_status !== 1 ? (
                <ElButton size="small" plain onClick={() => remindMessFn(row)}>
                    提醒发送
                </ElButton>
            ) : (
                '--'
            );
        }
    }
];

export default detailParticularsTableOption;
